package com.Cychat.schedule.controller;

import com.Cychat.commons.entity.ResultMessage;
import com.Cychat.commons.entity.pojo.PetSchedule;
import com.Cychat.schedule.service.PetScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Date;

@RestController
@RequestMapping("/api/schedule/schedules")
@CrossOrigin
public class PetScheduleController {

    @Autowired
    private  PetScheduleService petScheduleService;

    /**
     * Description : 根据用户ID查询宠物日程列表
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     *
     * @param ownerId
     * @return java.util.List<com.Cychat.commons.entity.pojo.PetSchedule>
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @GetMapping("/owner/{ownerId}/{userId}")
    public ResultMessage<List<PetSchedule>> getSchedulesByOwnerId(@PathVariable("ownerId") Integer ownerId, @PathVariable("userId") Long userId) {
        List<PetSchedule> schedulesByOwnerId = petScheduleService.getSchedulesByOwnerId(ownerId);
        return ResultMessage.success(schedulesByOwnerId);
    }
    /**
     * Description : 根据日程提醒ID查询宠物日程列表
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     * @param scheduleId
     * @return java.util.List<com.Cychat.commons.entity.pojo.PetSchedule>
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @GetMapping("/pet/{scheduleId}/{userId}")
    public ResultMessage<List<PetSchedule>> getSchedulesByScheduleId(@PathVariable("scheduleId") Integer scheduleId, @PathVariable("userId") Long userId) {
        List<PetSchedule> schedulesByScheduleId = petScheduleService.getSchedulesByScheduleId(scheduleId);
        return ResultMessage.success(schedulesByScheduleId);
    }
    /**
     * Description : 根据日期和用户ID查询宠物日程列表
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     *
     * @param ownerId
     * @param scheduleDate
     * @return java.util.List<com.Cychat.commons.entity.pojo.PetSchedule>
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @GetMapping("/date/{ownerId}/{userId}")
    public ResultMessage<List<PetSchedule>> getSchedulesByDate(
            @PathVariable("ownerId") Integer ownerId,
            @PathVariable("userId") Long userId,
            @RequestParam("schedule_date") Date scheduleDate) {
        return ResultMessage.success(petScheduleService.getSchedulesByDateAndOwnerId(scheduleDate, ownerId));
    }
    /**
     * Description : 添加宠物日程
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     *
     * @param schedule
     * @return boolean
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @PostMapping("/addSchedule/{userId}")
    public ResultMessage<Boolean> addSchedule(@PathVariable("userId") Long userId, @RequestBody PetSchedule schedule) {
        return ResultMessage.success(petScheduleService.save(schedule));
    }
    /**
     * Description : 更新宠物日程
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     *
     * @param scheduleId
     * @param schedule
     * @return boolean
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @PutMapping("/updateSchedule/{scheduleId}/{userId}")
    public ResultMessage<Boolean> updateSchedule(
            @PathVariable("scheduleId") Integer scheduleId,
            @PathVariable("userId") Long userId,
            @RequestBody PetSchedule schedule) {
        schedule.setScheduleId(scheduleId);
        return ResultMessage.success(petScheduleService.updateById(schedule));
    }
    /**
     * Description : 删除宠物日程
     * ChangeLog : 1. 创建 (2025/10/29 10:20 [Lenovo]);
     *
     * @param scheduleId
     * @return boolean
     * @auther: 谢宝辉
     * date: 2025/10/29:10:20
     */
    @DeleteMapping("/deleteSchedule/{scheduleId}/{userId}")
    public ResultMessage<Boolean> deleteSchedule(@PathVariable("scheduleId") Integer scheduleId, @PathVariable("userId") Long userId) {
        return ResultMessage.success(petScheduleService.removeById(scheduleId));
    }
}